import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Font;

import ulj2me.*;

interface IPMNPages 
{
//	PMN_PAGES
	final byte N_PAGE1=JULFrame.N_USER;
	final byte N_PAGE2=JULFrame.N_USER+1;
	final byte N_PAGE3=JULFrame.N_USER+2;	
	
	final byte PMN_MAIN=JULFrame.N_USER+40;
	final byte PMN_EXIT=PMN_MAIN;
	final byte PMN_MAIN_THEME=JULFrame.N_USER+45;
	final byte PMN_PAGES=JULFrame.N_USER+50;
}

public class JFrmMain extends JULFrame implements IPMNPages
{
//	JFrmPage1 page1;
//	JFrmPage2 page2;
	static int m_nThemeCount;
	
	JULStatus m_status;
	public JFrmMain()
	{
		super();
		int m_nThemeCount=0;
	}
	void Page(int nPage)
	{
		System.out.println(""+nPage);
		JULFrame page;
		switch(nPage)
		{
		case 1:
			page=(JULFrame)(new JFrmPage1());
			break;
		case 2:
			page=(JULFrame)(new JFrmPage2());
			break;
		case 3:
			page=(JULFrame)(new JFrmPage3());
			break;
		default:
			return;
		}
		page.Create(this);
		page.Master();
	}
	public static void FillVertMenu(JULPopupMenu pm)
	{
		JULThemeParser theme=new JULThemeParser();
		m_nThemeCount=theme.GetCount();
		for(int i=0;i<m_nThemeCount;++i)
			pm.AddItem("/"+theme.GetName(i)+".png",theme.GetName(i),PMN_MAIN_THEME+i);
		pm.AddItem("exit",PMN_EXIT);
	}
	public static boolean IsMainMsg(byte nType)
	{
		if((nType>=PMN_MAIN_THEME)&&(nType<(PMN_MAIN_THEME+m_nThemeCount)))
		{
			JULThemeParser theme=new JULThemeParser();
			theme.SetCurrent(nType-PMN_MAIN_THEME);
			JULWorkSpace.ThemeChange();
			return true;
		}
		switch(nType)
		{
		case PMN_EXIT:
			JULMIDlet.GetMIDlet().notifyDestroyed();
			break;
		}
		return false;
	}
	//=========================================
	public void OnCreate()
	{
		super.OnCreate();
		m_status=new JULStatus();
		m_status.Create();
		Font font=JULWorkSpace.GetDefaultFont();
		int nSize1=font.stringWidth("128");
		int nSize2=font.stringWidth("100%");
		int nSize3=font.stringWidth(">100");
		m_status.AddPaneText("text1",50);
		m_status.AddPaneSep();
		m_status.AddPaneImage("/MMenuItem.png");
		m_status.AddPaneText("128",nSize1);
		m_status.AddPaneSep();
		m_status.AddPaneImage("/MMenuItem.png");
		m_status.AddPaneText("99%",nSize2);
		m_status.AddPaneSep();
		m_status.AddPaneImage("/MMenuItem.png");
		m_status.AddPaneText(">100",nSize3);
		m_status.SetPaneTextWidth(0,m_rectWnd.cx-m_status.GetWidthRange(1,9));
		m_status.Show(true);
		m_status.SetPaneText(6,"99%");
		
		Page(2);
	}

	public void OnCmd(JULWnd wndSender,byte nType)
	{
		switch(nType)
		{
		case N_PAGE1:
			Page(1);
			break;
		case N_PAGE2:
			Page(2);
			break;
		case N_PAGE3:
			Page(3);
			break;			
		}
	}	
}